package ferp.core.ai.tree2;

/**
 * User: igorgok
 * Date: 1/26/12 11:59 AM
 */
final class Level
{
  // current round
  public final int round;
  // node lists
  public final LinkedList<Node> pending = new LinkedList<Node>(Node.class);
  public final LinkedList<Node> processed = new LinkedList<Node>(Node.class);
  public final LinkedList<Node> complete = new LinkedList<Node>(Node.class);

  public Level(int round)
  {
    this.round = round;
  }

  public final void clear(Node excluded)
  {
    clear(pending, excluded);
    clear(processed, excluded);
    clear(complete, excluded);
  }

  // clear list destroying every node in it
  private void clear(LinkedList<Node> list, Node excluded)
  {
    for (list.start(); list.hasNextEntry(); /**/)
    {
      Node n = list.nextEntry();

      // all nodes except the excluded one
      if (n != excluded)
      {
        // remove it from the list
        list.removeCurrentEntry();
        // detach children and put the position back to the pool
        n.destroy();
      }
    }
  }
}
